local skel = fk.CreateSkill {
  name = "rmt__miaoduan",
  tags = { Skill.Compulsory, Skill.Lord },
  dynamic_desc = function(self, player)
    return "主公技，锁定技，你于秦势力角色回合使用第{"..player:getMark("rmt__miaoduan").."}张牌后，本回合你的手牌均视为【酒】直至你使用牌。非反贼角色死亡后，{}数字-1。"
  end,
}

skel:addEffect(fk.CardUseFinished, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player.room.current and player.room.current.kingdom == "qin" and
    #player.room.logic:getEventsByRule(GameEvent.UseCard, 999, function (e)
      return e.data.from == player
    end, nil, Player.HistoryTurn) == player:getMark("rmt__miaoduan")
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@rmt__miaoduan-turn", 1)
  end,
})

skel:addEffect("filter", {
  card_filter = function(self, card, player)
    return player:getMark("@@rmt__miaoduan-turn") > 0 and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, player, to_select)
    local card = Fk:cloneCard("analeptic", to_select.suit, to_select.number)
    card.skillName = skel.name
    return card
  end,
})

skel:addEffect(fk.AfterCardUseDeclared, {
  can_refresh = function(self, event, target, player, data)
    return player:getMark("rmt__miaoduan") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@rmt__miaoduan-turn", 0)
  end,
})

skel:addEffect(fk.Death, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(skel.name, true) and target.role ~= "rebel" and player:getMark("rmt__miaoduan") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "rmt__miaoduan", 1)
  end,
})

skel:addAcquireEffect(function (self, player, is_start)
  player.room:setPlayerMark(player, "rmt__miaoduan", 2)
end)

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "rmt__miaoduan", 0)
end)

Fk:loadTranslationTable{
  ["rmt__miaoduan"] = "庙短",
  [":rmt__miaoduan"] = "主公技，锁定技，你于秦势力角色回合使用第{2}张牌后，本回合你的手牌均视为【酒】直至你使用牌。非反贼角色死亡后，{}数字-1。",

  ["@@rmt__miaoduan-turn"] = "庙短",

  ["$rmt__miaoduan1"] = "庙堂食禄者，忠义不及三寸...",
  ["$rmt__miaoduan2"] = "殿陛沐冠者，气节不过三步...",
}

return skel
